<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>NutzBook demo</title>
	<!-- 导入jquery -->
	<script type="text/javascript" src="js/jquery-1.6.4.js"></script>
	<!-- 把user id复制到一个js变量 -->
	<script type="text/javascript">
	    var me = '${me}';
	    var base = '${base}';
	    $(function() {
	        $("#login_button").click(function() {
	            $.ajax({
	                url : base + "/user/login",
	                type: "POST",
	                data:$('#loginForm').serialize(),
	                error: function(request) {
	                    alert("Connection error");
	                },
	                dataType:"json",
	                success: function(data) {
	                    if (data == true) {
	                        location.reload();
	                    } else {
	                        alert("登陆失败,请检查账号密码")
	                    }
	                }
	            });
	            return false;
	        });
	        if (me) {
	            $("#login_div").hide();
	            $("#userInfo").html("您的Id是" + me);
	            $("#user_info_div").show();
	        } else {
	            $("#login_div").show();
	            $("#user_info_div").hide();
	        }
	    });
	</script>
</head>
<body>
	<div id="login_div">
	    <form action="#" id="loginForm" method="post">
	        用户名 <input name="username" type="text" value="admin">
	        密码 <input name="password" type="password" value="123456">
	        <button id="login_button">提交</button>
	    </form>
	</div>
	<div id="user_info_div">
	    <p id="userInfo"></p>
	    <a href="${base }/user">用户列表</a>
	    <a href="${base }/user/profile">修改资料</a>
	    <a href="${base}/user/logout">登出</a>
	</div>
</body>
</html>